/*
 * Copyright (C) 2008-2011 CBDP Consortium
 * 
 * All rights reserved.
 *
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution.
 * 
 * This software consists of contributions made by many individuals, 
 * listed below:
 *
 * Author: 	Xabier Laiseca <xabier.laiseca@deusto.es>
 * 			David Ausín <david.ausin@deusto.es>
 */
package cbdp.server.contextreasoner.internal.containers;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.tdb.TDBFactory;
import com.hp.hpl.jena.tdb.solver.reorder.ReorderLib;
import com.hp.hpl.jena.tdb.sys.SystemTDB;

public class TDBOntologyContainer extends BaseOntologyContainer
{

	@Override
	public void load()
	{
		if (SystemTDB.defaultOptimizer == null)
		{
			SystemTDB.defaultOptimizer = ReorderLib.identity();
		}
		
		//final String storageConfigurationFile = getConfiguration().getStorageConfigurationFileLocation();
		//final URL storageConfigurationFileUrl = TDBOntologyContainer.class.getResource(storageConfigurationFile);
		//final Model spec = TDBFactory.assembleModel(storageConfigurationFileUrl.toString());
		final String storageConfigurationFile = 
					(getConfiguration().getStorageConfigurationFileLocation() != null)?
					getConfiguration().getStorageConfigurationFileLocation():
					"/resources/configuration/tdb.ttl";
					
		final Model spec = TDBFactory.assembleModel(storageConfigurationFile);
		setOntModel(ModelFactory.createOntologyModel(getOntModelSpec(), spec));
	}

	@Override
	public void close()
	{
		getOntModel().commit();
		getOntModel().close();
	}

}
